
// 全局变量
var src1;
var src2;
var src3;
var src4;
var src5;
var src6;
var src7;
var src8;
var src9;

var compressImgSrc1;
var compressImgSrc2;
var compressImgSrc3;
var compressImgSrc4;
var compressImgSrc5;
var compressImgSrc6;
var compressImgSrc7;
var compressImgSrc8;
var compressImgSrc9;

var cityStorage;
var compantyTypeStorage;
var nameStorage;
var sexStorage;
var sfStorage;
var jszStorage;
var carStorage;
var recordStorage;
var typeNumStorage;

var carNumberStorage;
var carBrandStorage;
var carBrandModelStorage;
var carFisrDataStorage;
var carNumberStorage;
var carOwnerStorage;
var userId;
var certificateNumStorage;

var idCardPositiveImage;
var idCardOppositeImage;
var vehicleImage;
var jszImage;
var jszCopyImage;
var xszImage;
var xszCopyImage;
var workLicenseImage;
var driverFhoImage;
var jszValidityPeriod;

var channelId;

var userId;  
$(function(){


    userId=sessionStorage.getItem("userIdName"); 
    //驾驶员信息读取
    cityStorage = sessionStorage.getItem("cityName");
    console.log(cityStorage);
    compantyTypeStorage = sessionStorage.getItem("compantyType");
    console.log(compantyTypeStorage);
    nameStorage = sessionStorage.getItem("name");
    sexStorage = sessionStorage.getItem("sex");
    console.log(sexStorage);
    sfStorage = sessionStorage.getItem("idCard");
    jszStorage =sessionStorage.getItem("driLicDate");
    carStorage =sessionStorage.getItem("carType");
    recordStorage =sessionStorage.getItem("licDataNo");
    typeNumStorage = sessionStorage.getItem("typeNum");
    jszValidityPeriod = sessionStorage.getItem("lastDate");
    // 车辆信息读取
    carNumberStorage= sessionStorage.getItem("carNumber");
    carBrandStorage = sessionStorage.getItem("carBrandType");
    carBrandModelStorage = sessionStorage.getItem("carBrandModel");
    carFisrDataStorage = sessionStorage.getItem("carFisrData");
    carOwnerStorage = sessionStorage.getItem("carOwner");
    carJzStorage = sessionStorage.getItem("carCjz");
    certificateNumStorage = sessionStorage.getItem("certificateNum");
    //通过扫二维码获取相应渠道表识
    channelId = sessionStorage.getItem("QRCodeHistory");
    
    //访问接口 判断此userId是否有数据
    $.ajax({
            type: "post",
            url:baseUrl+"/dingding-web/driverAction!getDriverAuthInfo.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data:{
                userId:userId
            },
            success: function(data){ 
            if(data.code == 200){  
                console.log(data);
                        //获取此 userId src地址 
                        src1 = data.responseBody.idCardPositiveImageUrl;
                        src2 = data.responseBody.idCardOppositeImageUrl;
                        src3 = data.responseBody.vehicleImageUrl;
                        src4 = data.responseBody.jszImageUrl;
                        src5 = data.responseBody.jszCopyImageUrl;
                        src6 = data.responseBody.xszImageUrl;
                        src7 = data.responseBody.xszCopyImageUrl;                    
                        src8 = data.responseBody.workLicenseImageUrl;
                        src9 = data.responseBody.userAvatarUrl; 
                        
                        //根据后台反馈userId 更改images src
                        $("#blah1").attr("src",src1);
                        $(".jiaNo1").empty();
                        $(".textNo1").empty();
                        $(".sfzFrontBtn").css("background","#FF4C4B");
                        $(".sfzFrontBtn").html("上传成功");

                        $("#blah2").attr("src",src2);
                        $(".jiaNo2").empty();
                        $(".textNo2").empty();
                        $(".sfzCopyBtn").css("background","#FF4C4B");
                        $(".sfzCopyBtn").html("上传成功");

                        $("#blah3").attr("src",src3);
                        $(".jiaNo3").empty();
                        $(".textNo3").empty();
                        $(".driverCarBtn").css("background","#FF4C4B");
                        $(".driverCarBtn").html("上传成功");

                        $("#blah4").attr("src",src4);
                        $(".jiaNo4").empty();
                        $(".textNo4").empty();
                        $(".licenceFrontBtn").css("background","#FF4C4B");
                        $(".licenceFrontBtn").html("上传成功");


                        $("#blah5").attr("src",src5);
                        $(".jiaNo5").empty();
                        $(".textNo5").empty();
                        $(".licenceCopyBtn").css("background","#FF4C4B");
                        $(".licenceCopyBtn").html("上传成功");

                        $("#blah6").attr("src",src6);
                        $(".jiaNo6").empty();
                        $(".textNo6").empty();
                        $(".runFrontBtn").css("background","#FF4C4B");
                        $(".runFrontBtn").html("上传成功");

                        $("#blah7").attr("src",src7);
                        $(".jiaNo7").empty();
                        $(".textNo7").empty();
                        $(".runCopyBtn").css("background","#FF4C4B");
                        $(".runCopyBtn").html("上传成功");

                        $("#blah8").attr("src",src8);
                        $(".jiaNo8").empty();
                        $(".textNo8").empty();
                        $(".certificationBtn").css("background","#FF4C4B");
                        $(".certificationBtn").html("上传成功");

                        $("#blah9").attr("src",src9);
                        $(".jiaNo9").empty();
                        $(".textNo9").empty();
                        $(".driverFhoBtn").css("background","#FF4C4B");
                        $(".driverFhoBtn").html("上传成功");
                        
                        //从后台获取Image name 用于传值访问url
                        idCardPositiveImage = data.responseBody.idCardPositiveImage;
                        idCardOppositeImage = data.responseBody.idCardOppositeImage;
                        jszCopyImage = data.responseBody.jszCopyImage;
                        jszImage = data.responseBody.jszImage;
                        vehicleImage = data.responseBody.vehicleImage;
                        workLicenseImage = data.responseBody.workLicenseImage;
                        xszCopyImage = data.responseBody.xszCopyImage;
                        xszImage = data.responseBody.xszImage;
                        driverFhoImage = data.responseBody.userAvatar;
                   
                        // 提交审核 认证车主
                        $(".carBtn").on("click",function(){
                          $.ajax({
                                type: "post",
                                url: baseUrl+"/dingding-web/driverAction!driverAuth.action",
                                dataType: "jsonp",
                                async: false,
                                jsonp: "callback",
                                jsonpCallback: "success_jsonp",
                                data:{
                                    "authType":typeNumStorage,
                                    "cityId":cityStorage,
                                    "idCard":sfStorage,
                                    "idCardOppositeImage":idCardOppositeImage,
                                    "idCardPositiveImage":idCardPositiveImage,
                                    "jszCopyImage":jszCopyImage,
                                    "jszFileNumber":recordStorage,
                                    "jszImage":jszImage,
                                    "jszLssueDate":jszStorage,
                                    "lisencePlate":carNumberStorage,
                                    "permittedType":carStorage,
                                    "sex":sexStorage,
                                    "trueName":nameStorage,
                                    "organizationId":compantyTypeStorage,
                                    "userId":userId, 
                                    "vehicleImage":vehicleImage,
                                    "vehicleModel":carBrandModelStorage,
                                    "vehicleNumber":carJzStorage,
                                    "vehicleOwner":carOwnerStorage,
                                    "vehicleType":carBrandStorage,
                                    "workLicenseImage":workLicenseImage,
                                    "workLicenseNumber":certificateNumStorage,
                                    "xszImage":xszImage,
                                    "xszLssueDate":carFisrDataStorage,
                                    "jszValidityPeriod":jszValidityPeriod,
                                    "userAvatar":driverFhoImage,
                                    "channelId":channelId,
                                    "xszCopyImage":xszCopyImage
                                },
                                success: function(data){
                                    if(data.code == 200){
                                        window.location.href="checking.html";
                                    }else{
                                        var message = data.errorMessage;
                                        swal({
                                            title:message,
                                            type: "warning",
                                            confirmButtonColor: "#DD6B55",
                                            confirmButtonText: "确定",
                                        });
                                    }
                                }
                            });         
                        })
                     }else if(data.code ==  600){
                        // 提交审核 认证车主
                        $(".carBtn").on("click",function(){
                          $.ajax({
                                type: "post",
                                url: baseUrl+"/dingding-web/driverAction!driverAuth.action",
                                dataType: "jsonp",
                                async: false,
                                jsonp: "callback",
                                jsonpCallback: "success_jsonp",
                                data:{
                                    "authType":typeNumStorage,
                                    "cityId":cityStorage,
                                    "idCard":sfStorage,
                                    "idCardOppositeImage":idCardOppositeImage,
                                    "idCardPositiveImage":idCardPositiveImage,
                                    "jszCopyImage":jszCopyImage,
                                    "jszFileNumber":recordStorage,
                                    "jszImage":jszImage,
                                    "jszLssueDate":jszStorage,
                                    "lisencePlate":carNumberStorage,
                                    "permittedType":carStorage,
                                    "sex":sexStorage,
                                    "trueName":nameStorage,
                                    "organizationId":compantyTypeStorage,
                                    "userId":userId, 
                                    "vehicleImage":vehicleImage,
                                    "vehicleModel":carBrandModelStorage,
                                    "vehicleNumber":carJzStorage,
                                    "vehicleOwner":carOwnerStorage,
                                    "vehicleType":carBrandStorage,
                                    "workLicenseImage":workLicenseImage,
                                    "workLicenseNumber":certificateNumStorage,
                                    "xszImage":xszImage,
                                    "xszLssueDate":carFisrDataStorage,
                                    "jszValidityPeriod":jszValidityPeriod,
                                    "userAvatar":driverFhoImage,
                                    "channelId":channelId,
                                    "xszCopyImage":xszCopyImage
                                },
                                success: function(data){
                                    if(data.code == 200){
                                        window.location.href="checking.html";
                                    }else{
                                        var message = data.errorMessage;
                                        swal({
                                            title:message,
                                            type: "warning",
                                            confirmButtonColor: "#DD6B55",
                                            confirmButtonText: "确定",
                                        });
                                    }
                                }
                            });         
                        })

                     } 
                 

            }
        });

     
    //取消模态框
    $('#myModal1').modal('hide')

         //点击调取 身份证正面照片
        $(".sfzFrontBox").on("click",function(){
              $("#sfzFront").css("display","block");
        })

       // 身份证正面照片上传
       function readURL1(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#sfzFront").css("display","none");
                     $(".jiaNo1").empty();
                     $(".textNo1").empty();
                     $("#blah1").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp1").change(function(){
             readURL1(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc1 = rst.base64;
                sfzFrontFunction(compressImgSrc1);                
            })
            
      });



      //点击调取 身份证副本照片
        $(".sfzCopyBox").on("click",function(){
              $("#sfzCopy").css("display","block");
        })

       // 身份证副本照片上传
       function readURL2(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#sfzCopy").css("display","none");
                     $(".jiaNo2").empty();
                     $(".textNo2").empty();
                     $("#blah2").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp2").change(function(){
             readURL2(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc2 = rst.base64;
                sfzCopyFunction(compressImgSrc2);    
            })
      });



      //点击调取 人车合影照片
        $(".driverCarBox").on("click",function(){
              $("#driverCar").css("display","block");
        })

       // 人车合影照片上传
       function readURL3(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#driverCar").css("display","none");
                     $(".jiaNo3").empty();
                     $(".textNo3").empty();
                     $("#blah3").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp3").change(function(){
             readURL3(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc3 = rst.base64;
                driverCarFunction(compressImgSrc3);    
            })
      });



      //点击调取 驾驶证正面照
        $(".jszFrontBox").on("click",function(){
              $("#jszFront").css("display","block");
        })

       // 驾驶证正面照上传
       function readURL4(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#jszFront").css("display","none");
                     $(".jiaNo4").empty();
                     $(".textNo4").empty();
                     $("#blah4").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp4").change(function(){
             readURL4(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc4 = rst.base64;
                licenceFrontFunction(compressImgSrc4);    
            })
            
      });



      //点击调取 驾驶证副本
        $(".jszCopyBox").on("click",function(){
              $("#jszCopy").css("display","block");
        })

       // 驾驶证副本照上传
       function readURL5(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#jszCopy").css("display","none");
                     $(".jiaNo5").empty();
                     $(".textNo5").empty();
                     $("#blah5").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp5").change(function(){
             readURL5(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc5 = rst.base64;
                licenceCopyFunction(compressImgSrc5);    
            })
      });



      //点击调取 行车证正本
        $(".runFrontBox").on("click",function(){
              $("#runFront").css("display","block");
        })

       // 行车证正本照上传
       function readURL6(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#runFront").css("display","none");
                     $(".jiaNo6").empty();
                     $(".textNo6").empty();
                     $("#blah6").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp6").change(function(){
             readURL6(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc6 = rst.base64;
                runFrontFunction(compressImgSrc6);    
            })
      });


      //点击调取 行车证副本
        $(".runCopyBox").on("click",function(){
              $("#runCopy").css("display","block");
        })

       // 行车证正本照副本
       function readURL7(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#runCopy").css("display","none");
                     $(".jiaNo7").empty();
                     $(".textNo7").empty();
                     $("#blah7").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp7").change(function(){
             readURL7(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc7 = rst.base64;
                runCopyFunction(compressImgSrc7);    
            })
      });


        //点击调取 司机个人一寸照
        $(".driverFhoBox").on("click",function(){
              $("#driverFho").css("display","block");
        })

       //  司机个人一寸照
       function readURL9(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#driverFho").css("display","none");
                     $(".jiaNo9").empty();
                     $(".textNo9").empty();
                     $("#blah9").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp9").change(function(){
             readURL9(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc9 = rst.base64;
                driverFhoFunction(compressImgSrc9);    
            })
      });


      //点击调取 从业资格证
        $(".certificationBox").on("click",function(){
              $("#certificationMb").css("display","block");
        })

       //  从业资格证照副本
       function readURL8(input) {
             if (input.files && input.files[0]) {
                 var reader = new FileReader();
                 reader.onload = function (e) {
                     $("#certificationMb").css("display","none");
                     $(".jiaNo8").empty();
                     $(".textNo8").empty();
                     $("#blah8").attr("src",e.target.result);
                 }
                 reader.readAsDataURL(input.files[0]);
             }
      }
      $("#imgInp8").change(function(){
             readURL8(this);
             // 压缩img
             lrz(this.files[0], {width: 640})
             .then(function (rst) {
                compressImgSrc8 = rst.base64;
                certificationFunction(compressImgSrc8);     
            })
      });

})

//封装合影规则 弹框方法
function mtTest(){
    $('#myModal').modal('show');
}

//上传身份证正面封装函数
function sfzFrontFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc1,
                userId:userId
            },
            success:function(data){
                console.log(data);
                if(data.code==200){       
                  idCardPositiveImage = data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil1").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont1").html("上传失败,请重新上传");
                  $(".Veil1").css("display","block");
                }
            }
        }); 
}

//上传身份证副本
function sfzCopyFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc2,
                userId:userId
            },
            success:function(data){
                console.log(data);
                if(data.code==200){       
                  idCardOppositeImage =  data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil2").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont2").html("上传失败,请重新上传");
                  $(".Veil2").css("display","block");
                }

            }
        }); 
}

//上传人车合影
function driverCarFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc3,
                userId:userId
            },
            success:function(data){
                console.log(data);
                if(data.code==200){       
                  vehicleImage =  data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil3").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont3").html("上传失败,请重新上传");
                  $(".Veil3").css("display","block");
                }
            }
        }); 
}

//上传驾驶证正面
function licenceFrontFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc4,
                userId:userId
            },
            success:function(data){
                console.log(data); 
                if(data.code==200){       
                  jszImage = data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil4").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont4").html("上传失败,请重新上传");
                  $(".Veil4").css("display","block");
                }
            }
        }); 
}


//上传驾驶证副本
function licenceCopyFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc5,
                userId:userId
            },
            success:function(data){
                console.log(data);
                if(data.code==200){       
                  jszCopyImage = data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil5").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont5").html("上传失败,请重新上传");
                  $(".Veil5").css("display","block");
                }
            }
            
        }); 
}


//上传行驶证正本
function runFrontFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc6,
                userId:userId
            },
            success:function(data){
                console.log(data);
                if(data.code==200){       
                  xszImage = data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil6").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont6").html("上传失败,请重新上传");
                  $(".Veil6").css("display","block");
                }
            }
        }); 
}


//上传行驶证副本
function runCopyFunction(){
    $(".alert_sc").css("display","block");
        $.ajax({
            type: "post",
            url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                uploadPictures:compressImgSrc7,
                userId:userId
            },
            success:function(data){
                console.log(data);
                if(data.code==200){       
                  xszCopyImage = data.responseBody.imageName;
                  $(".alert_sc").css("display","none");
                  $(".Veil7").css("display","block");
                }else{
                  $(".alert_sc").css("display","none");
                  $(".VeilFont7").html("上传失败,请重新上传");
                  $(".Veil7").css("display","block");
                }
            }
        }); 
}

//上传司机个人一寸照
function driverFhoFunction(){
$(".alert_sc").css("display","block");
    $.ajax({
        type: "post",
        url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
        dataType: "jsonp",
        async: false,
        jsonp: "callback",
        jsonpCallback: "success_jsonp",
        data: {
            uploadPictures:compressImgSrc9,
            userId:userId
        },
        success:function(data){
            console.log(data);
            if(data.code==200){       
              driverFhoImage = data.responseBody.imageName;
              $(".alert_sc").css("display","none");
              $(".Veil9").css("display","block");
            }else{
              $(".alert_sc").css("display","none");
              $(".VeilFont9").html("上传失败,请重新上传");
              $(".Veil9").css("display","block");
            }
        }
    }); 
}

//上传从业资格证
function certificationFunction(){
    $(".alert_sc").css("display","block");
    $.ajax({
        type: "post",
        url: baseUrl+"/dingding-web/driverAction!uploadDriverAuthImage.action",
        dataType: "jsonp",
        async: false,
        jsonp: "callback",
        jsonpCallback: "success_jsonp",
        data: {
            uploadPictures:compressImgSrc8,
            userId:userId
        },
        success:function(data){
            console.log(data);
            if(data.code==200){       
              workLicenseImage = data.responseBody.imageName;
              $(".alert_sc").css("display","none");
              $(".Veil8").css("display","block");
            }else{
              $(".alert_sc").css("display","none");
              $(".VeilFont8").html("上传失败,请重新上传");
              $(".Veil8").css("display","block");
            }
        }
    }); 
}
